package user;

import javax.servlet.*;
import javax.servlet.http.*;
import javax.servlet.annotation.*;
import java.io.IOException;

import cake.UserDao;
import cake.UserDaoImpl;

@WebServlet(name = "UpdateServlet", value = "/UpdateServlet")
public class UpdateServlet extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        doPost(req, resp);
    }

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        req.setCharacterEncoding("utf-8");
        resp.setCharacterEncoding("utf-8");
        resp.setContentType("text/html;charset=utf-8");
        String data=req.getParameter("data");

        String id = req.getParameter("id");
        String shop = req.getParameter("shop");
        String detail = req.getParameter("detail");
        String price = req.getParameter("price");
        String num = req.getParameter("num");
        UserDao ud = new UserDaoImpl();
        if(ud.update(id, shop, detail, price, num)){
            req.getRequestDispatcher("SearchAllServlet").forward(req, resp);
        }else{
            resp.sendRedirect("error.jsp");
        }
    }
}
